package cn.tradewin.advisor.pages.master;

import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.slf4j.Logger;

import cn.tradewin.advisor.commons.selectmodel.CodeLabelSelectModel;
import cn.tradewin.advisor.commons.util.CodeTableSymbols;
import cn.tradewin.advisor.commons.util.LanguageSymbols;
import cn.tradewin.advisor.persist.model.CalendarCategory;
import cn.tradewin.advisor.persist.services.CalendarService;
import cn.tradewin.advisor.persist.services.CodetableService;

public class CalendarCategoryAdd {
	
	@Inject
	private Logger log;
	
	@Property
	private CalendarCategory category;
	
	@Property
	private CodeLabelSelectModel localeSelectModel;
	
	@Inject
	private CalendarService calendarService;
	
	@Inject
	private CodetableService codetableService;
	
	void setupRender() {
		localeSelectModel = new CodeLabelSelectModel(codetableService.listCategory(CodeTableSymbols.COUNTRY_TYPE, LanguageSymbols.ZH));
	}
	
	
	void onPrepare() {
		if (category == null) {
			category = new CalendarCategory();
		}
	}
		
	Object onSuccess() {
		calendarService.addCalendarCategory(category);
		return CalendarCategoryBoard.class;
	}
}
